<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item label="渠道商" prop="useruuid">
					<el-select v-model="filters.useruuid" placeholder="请选择渠道商" clearable filterable>
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in users"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-input v-model="filters.dowonphonenum" placeholder="手机号码" clearable></el-input>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="date" placeholder="开始时间" format="yyyy-MM-dd"  clearable v-model="filters.starttime"
									style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="date" placeholder="结束时间" format="yyyy-MM-dd" clearable v-model="filters.endtime"
									style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getdownFund">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="refunds" highlight-current-row v-loading="listLoading" border max-height="620" style="width: 100%;">
			<el-table-column type="index" width="80" label="编号">
			</el-table-column>
			<el-table-column prop="user.username" label="渠道商" show-overflow-tooltip  width="220"  >
			</el-table-column>
			<el-table-column prop="downRechargeFlow.dowonphonenum" label="手机号码" width="130"   >
			</el-table-column>
			<el-table-column prop="downrefundamount" label="退款金额" width="130">
			</el-table-column>
			<el-table-column prop="balance" label="退款后余额"  show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="downrefundstatus" label="退款状态"  width="130" :formatter="refundStatus" >
			</el-table-column>
			<el-table-column prop="downrefundtime" label="退款时间" min-width="220" >
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>

	</section>
</template>

<script>
    import util from '../../common/js/util'
    //import NProgress from 'nprogress'
    import {getdownFund,findAllDownShopInfo } from '../../api/api';
    import moment from 'moment';
    export default {
        data() {
            return {
                filters: {
                    useruuid: '',
                    dowonphonenum:'',
					starttime:moment(new Date(),"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD'),
					endtime:''
                },
                users: [],
                refunds:[],
                total: 0,
                start: 0,
                pageSize:10,
                listLoading: false,
            }
        },
        methods: {
            refundStatus(row, column){
                return row.downrefundstatus == 1 ? '退款成功' : "退款失败";
            },
            handleCurrentChange: function (val) {
				this.start = val - 1;
				this.getdownFund();
			},
			handleSizeChange: function (val) {
				this.pageSize = val;
				this.getdownFund();
			},
            getdownFund() {
				let para = {
					start : this.start,
					pageSize:this.pageSize,
					useruuid:  this.filters.useruuid == "0" ? "" :this.filters.useruuid,
					dowonphonenum: this.filters.dowonphonenum,
					starttime: (this.filters.starttime == "" || this.filters.starttime == undefined) ? "" : moment(this.filters.starttime,"YYYY-MM-DD").format('YYYY-MM-DD'),
					endtime:(this.filters.endtime == "" || this.filters.endtime == undefined) ? "" : moment(this.filters.endtime,"YYYY-MM-DD").format('YYYY-MM-DD'),
				};
                this.listLoading = true;
                //NProgress.start();
                getdownFund(para).then(res => {
                    let { message, code, data } = res;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						this.refunds =  data.result;
                        this.total = data.totalCount;
					}
                    this.listLoading = false;
                });
            }, findAllDownShopInfo: function () {
                let para = {useruuid:JSON.parse(sessionStorage.getItem("user")).useruuid};
                findAllDownShopInfo(para).then(datas => {
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.users =   data;
                    }
                });
            }
        },
        mounted() {
            this.findAllDownShopInfo();
            this.getdownFund();
        }
    }

</script>

<style scoped>

</style>
